package com.sophialex.health.record.views;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import org.eclipse.ui.part.ViewPart;

import com.sophialex.health.record.common.assist.HrPersonAssist;
import com.sophialex.health.record.dialog.HrPersonSelectDlg;
import com.sophialex.health.system.frame.assist.CommonAssist;
import com.sophialex.health.system.frame.assist.TextAssHelp;

public class PersonBasicView extends ViewPart {

	public static final String ID = "com.sophialex.health.record.views.PersonBasicView"; //$NON-NLS-1$
	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
	private Text text;
	private Text text_1;
	private Text text_2;
	private Text text_3;
	private Text text_4;
	private Text text_5;


	public PersonBasicView() {
	}

	/**
	 * Create contents of the view part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {


		parent.setLayout(new FillLayout(SWT.FILL));
		{
			ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
			toolkit.adapt(scrolledComposite);
			toolkit.paintBordersFor(scrolledComposite);
			scrolledComposite.setExpandHorizontal(true);
			scrolledComposite.setExpandVertical(true);
			Composite m = toolkit.createComposite(scrolledComposite, SWT.NONE);
			toolkit.paintBordersFor(m);
			{
				TableWrapLayout twl_container = new TableWrapLayout();
				twl_container.topMargin = 10;
				m.setLayout(twl_container);
			}
			Section base = toolkit.createSection(m,  Section.TWISTIE |  Section.TITLE_BAR);
			TableWrapData twd_base = new TableWrapData(TableWrapData.FILL, TableWrapData.TOP, 1, 1);
			twd_base.indent = 10;
			base.setLayoutData(twd_base);
			base.setExpanded(true);
			base.setText("\u57FA\u672C\u4FE1\u606F");
			
			Composite container = toolkit.createComposite(base, SWT.NONE);
			toolkit.paintBordersFor(container);
			{
				TableWrapLayout twl_container = new TableWrapLayout();
				twl_container.verticalSpacing = 12;
				twl_container.numColumns = 5;
				twl_container.horizontalSpacing = 10;
				twl_container.topMargin = 10;
				container.setLayout(twl_container);
			}
			//		{
			//			Label label = toolkit.createLabel(container, "个人基本信息", SWT.NONE);
			//			label.setFont(SWTResourceManager.getFont("宋体", 18, SWT.BOLD));
			//			TableWrapData twd_label = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 5);
			//			twd_label.valign = TableWrapData.MIDDLE;
			//			twd_label.align = TableWrapData.CENTER;
			//			label.setLayoutData(twd_label);
			//			
			//		}
					{
						Label label = toolkit.createLabel(container, "姓名", SWT.NONE);
						label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
					}
					{
						Composite composite = toolkit.createComposite(container, SWT.NONE);
						{
							TableWrapLayout twl_composite = new TableWrapLayout();
							twl_composite.numColumns = 2;
							composite.setLayout(twl_composite);
						}
						composite.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB, 1, 1));
						toolkit.paintBordersFor(composite);
						
						
						
						text = toolkit.createText(composite, "", SWT.NONE);
						TableWrapData twd_text = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE, 1, 1);
						twd_text.heightHint = 20;
						
						{
							Button button = toolkit.createButton(composite, "同名新增", SWT.NONE);
							button.setLayoutData(new TableWrapData(TableWrapData.FILL, TableWrapData.FILL, 1, 1));
							button.addSelectionListener(new SelectionAdapter() {
								
								public void widgetSelected(SelectionEvent e) {
									HrPersonSelectDlg dlg = new HrPersonSelectDlg(Display.getCurrent()
									                  					.getActiveShell(), text.getText());
									dlg.open();
								}
							});
						}
						
						text.setLayoutData(twd_text);
						
						text.addKeyListener(new KeyListener() {
							
							public void keyReleased(KeyEvent e) {
								if(e.keyCode == SWT.CR){
									MessageDialog.openInformation(null, "", "捕获到回车键，应该弹出窗口！");
								}
								
							}
							
							public void keyPressed(KeyEvent e) {
								// TODO Auto-generated method stub
								
							}
						});
					}
					
							{
								Label label = toolkit.createLabel(container, "身份证号", SWT.NONE);
								label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
							}
							{
								text_1 = toolkit.createText(container, "", SWT.NONE);
								TableWrapData twd_text_1 = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL, 1, 2);
								twd_text_1.valign = TableWrapData.MIDDLE;
								twd_text_1.heightHint = 20;
								text_1.setLayoutData(twd_text_1);
							}
							
							
							{
								Label label = toolkit.createLabel(container, "性别", SWT.NONE);
								label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
							}
							{
								Combo combo = new Combo(container, SWT.READ_ONLY| SWT.NONE);
								TableWrapData twd_combo = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE, 1, 1);
								twd_combo.heightHint = 20;
								combo.setLayoutData(twd_combo);
								combo.setItems(new String[] {"男", "女"});
								toolkit.adapt(combo);
								toolkit.paintBordersFor(combo);
								combo.select(0);
							}
							
									{
										Label label = toolkit.createLabel(container, "出生日期", SWT.NONE);
										label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
									}
									{
										DateTime dateTime = new DateTime(container, SWT.BORDER | SWT.DROP_DOWN);
										dateTime.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL, 1, 2));
										toolkit.adapt(dateTime);
										toolkit.paintBordersFor(dateTime);
									}
									
									
									{
										Label label = toolkit.createLabel(container, "联系电话", SWT.NONE);
										label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
									}
									{
										text_2 = toolkit.createText(container, "", SWT.NONE);
										TableWrapData twd_text_2 = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE, 1, 1);
										twd_text_2.heightHint = 20;
										text_2.setLayoutData(twd_text_2);
									}
									
											{
												Label label = toolkit.createLabel(container, "民族", SWT.NONE);
												label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
											}
											{
												Combo combo = new Combo(container, SWT.READ_ONLY);
												combo.setItems(new String[] {"汉族","少数民族"});
												combo.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL, 1, 1));
												toolkit.adapt(combo);
												toolkit.paintBordersFor(combo);
												combo.select(0);
											}
											{
												text_3 = toolkit.createText(container, "", SWT.NONE);
												TableWrapData twd_text_3 = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL, 1, 1);
												twd_text_3.valign = TableWrapData.MIDDLE;
												twd_text_3.heightHint = 20;
												text_3.setLayoutData(twd_text_3);
											}
											{
												Label label = toolkit.createLabel(container, "血型", SWT.NONE);
												label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
											}
											{
												Combo combo = new Combo(container, SWT.READ_ONLY);
												combo.setItems(new String[] {" O\u578B", "A\u578B", " B\u578B", "AB\u578B/RH\u9634\u6027(\u5426)", "AB\u578B/RH\u9634\u6027(\u662F)"});
												TableWrapData twd_combo = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE, 1, 1);
												twd_combo.heightHint = 20;
												combo.setLayoutData(twd_combo);
												toolkit.adapt(combo);
												toolkit.paintBordersFor(combo);
												combo.select(0);
											}
											{
												Label label = toolkit.createLabel(container, "文化程度", SWT.NONE);
												label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
											}
											{
												Combo combo = new Combo(container, SWT.READ_ONLY);
												combo.setItems(new String[] {"\u6587\u76F2\u534A\u6587\u76F2", "\u5C0F\u5B66", "\u521D\u4E2D", " \u9AD8\u4E2D\u6216\u4E2D\u4E13", "\u5927\u4E13\u53CA\u5927\u4E13\u4EE5\u4E0A", "\u4E0D\u8BE6"});
												TableWrapData twd_combo = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL, 1, 2);
												twd_combo.valign = TableWrapData.MIDDLE;
												combo.setLayoutData(twd_combo);
												toolkit.adapt(combo);
												toolkit.paintBordersFor(combo);
												combo.select(5);
											}
											{
												Label label = toolkit.createLabel(container, "婚姻", SWT.NONE);
												label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
											}
											{
												Combo combo = new Combo(container, SWT.READ_ONLY);
												combo.setItems(new String[] {"\u5DF2\u5A5A", "\u672A\u5A5A", "\u79BB\u5A5A", "\u4E27\u5076", "\u5176\u4ED6"});
												TableWrapData twd_combo = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1);
												twd_combo.heightHint = 20;
												twd_combo.valign = TableWrapData.MIDDLE;
												combo.setLayoutData(twd_combo);
												toolkit.adapt(combo);
												toolkit.paintBordersFor(combo);
												combo.select(0);
											}
											{
												Label label = toolkit.createLabel(container, "医疗费用支付方式", SWT.NONE);
												label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
											}
											{
												Combo combo = new Combo(container, SWT.READ_ONLY);
												combo.setItems(new String[] {"\u793E\u4F1A\u57FA\u672C\u533B\u7597\u4FDD\u9669", "\u5546\u4E1A\u533B\u7597\u4FDD\u9669", "\u5927\u75C5\u7EDF\u7B79", "\u65B0\u578B\u519C\u6751\u5408\u4F5C\u533B\u7597", "\u57CE\u9547\u5C45\u6C11\u57FA\u672C\u533B\u7597\u4FDD\u9669", "\u516C\u8D39\u533B\u7597", "\u5176\u4ED6"});
												TableWrapData twd_combo = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL, 1, 2);
												twd_combo.heightHint = 20;
												combo.setLayoutData(twd_combo);
												toolkit.adapt(combo);
												toolkit.paintBordersFor(combo);
												combo.select(0);
											}
											{
												Label label = toolkit.createLabel(container, "职业", SWT.NONE);
												label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
											}
											{
												Combo combo = new Combo(container, SWT.READ_ONLY);
												combo.setItems(new String[] {"\u79CD\u690D\u4E1A\u751F\u4EA7\u4EBA\u5458", "\u6797\u4E1A\u751F\u4EA7\u53CA\u91CE\u751F\u52A8\u690D\u7269\u4FDD\u62A4\u4EBA\u5458", "\u755C\u7267\u4E1A\u751F\u4EA7\u4EBA\u5458", "\u6E14\u4E1A\u751F\u4EA7\u4EBA\u5458", "\u6C34\u5229\u8BBE\u65BD\u7BA1\u7406\u517B\u62A4\u4EBA\u5458 ", "\u5176\u4ED6"});
												combo.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL, 1, 1));
												toolkit.adapt(combo);
												toolkit.paintBordersFor(combo);
												combo.select(0);
											}
											{
												text_4 = toolkit.createText(container, "", SWT.NONE);
												TableWrapData twd_text_4 = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE, 1, 3);
												twd_text_4.heightHint = 20;
												text_4.setLayoutData(twd_text_4);
											}
											
											
											base.setClient(container);
											
											
											Section opSec = toolkit.createSection(m,  Section.TWISTIE |  Section.TITLE_BAR);
											TableWrapData twd_opSec = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1);
											twd_opSec.indent = 10;
											opSec.setLayoutData(twd_opSec);
											opSec.setExpanded(true);
											opSec.setText("建档信息");
											
											Composite opContainer = toolkit.createComposite(opSec, SWT.NONE);
											toolkit.paintBordersFor(container);
											{
												TableWrapLayout twl_container = new TableWrapLayout();
												twl_container.verticalSpacing = 12;
												twl_container.numColumns = 5;
												twl_container.horizontalSpacing = 10;
												twl_container.topMargin = 10;
												opContainer.setLayout(twl_container);
											}
											opSec.setClient(opContainer);
											
											
											{
												Label label = toolkit.createLabel(opContainer, "  建档人", SWT.NONE);
												label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
											}
											{
												Combo combo = new Combo(opContainer, SWT.NONE);
												TableWrapData twd_combo = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE, 1, 1);
												twd_combo.heightHint = 20;
												combo.setLayoutData(twd_combo);
												toolkit.adapt(combo);
												toolkit.paintBordersFor(combo);
											}
											{
												Label label = toolkit.createLabel(opContainer, "建档日期", SWT.NONE);
												label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
											}
											{
												DateTime dateTime = new DateTime(opContainer, SWT.BORDER | SWT.DROP_DOWN);
												dateTime.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL, 1, 2));
												toolkit.adapt(dateTime);
												toolkit.paintBordersFor(dateTime);
											}
											
											{
												Label label = toolkit.createLabel(opContainer, "责任医生", SWT.NONE);
												label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
											}
											{
												Combo combo = new Combo(opContainer, SWT.NONE);
												TableWrapData twd_combo = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1);
												twd_combo.heightHint = 20;
												twd_combo.valign = TableWrapData.MIDDLE;
												combo.setLayoutData(twd_combo);
												toolkit.adapt(combo);
												toolkit.paintBordersFor(combo);
											}
											{
												Label label = toolkit.createLabel(opContainer, "      建档单位", SWT.NONE);
												label.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1));
											}
											{
												Combo combo = new Combo(opContainer, SWT.NONE);
												TableWrapData twd_combo = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL, 1, 2);
												twd_combo.valign = TableWrapData.MIDDLE;
												twd_combo.heightHint = 20;
												combo.setLayoutData(twd_combo);
												toolkit.adapt(combo);
												toolkit.paintBordersFor(combo);
											}
											scrolledComposite.setContent(m);
											scrolledComposite.setMinSize(m.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		}
//		{
//			Composite composite = toolkit.createComposite(m, SWT.NONE);
//			{
//				TableWrapLayout twl_composite = new TableWrapLayout();
//				twl_composite.numColumns = 2;
//				composite.setLayout(twl_composite);
//			}
//			composite.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB, 1, 1));
//			toolkit.paintBordersFor(composite);
//			{
//				text_5 = toolkit.createText(composite, "New Text", SWT.NONE);
//				text_5.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1));
//			}
//			{
//				Button button = toolkit.createButton(composite, "New Button", SWT.NONE);
//			}
//		}
        {
			CommonAssist assist = new HrPersonAssist(text, "name");
			TextAssHelp.addContentAss(assist, text, "name", false);
		}
		
		createActions();
		initializeToolBar();
		initializeMenu();
	}

	public void dispose() {
		toolkit.dispose();
		super.dispose();
	}

	/**
	 * Create the actions.
	 */
	private void createActions() {
		// Create the actions
	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
	}

	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		IMenuManager manager = getViewSite().getActionBars().getMenuManager();
	}

	@Override
	public void setFocus() {
		// Set the focus
	}
}
